<cfcomponent extends="assets.csac.com.Base">

	<cffunction name="get" access="public" output="false" returntype="assets.csac.com.bo.Product">
		<cfargument name="Product_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.Product_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new assets.csac.com.bo.Product();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new assets.csac.com.bo.Product();
			}
		</cfscript>
	</cffunction>

	<cffunction name="load" access="public" output="false" returntype="assets.csac.com.bo.Product">
		<cfargument name="obj" type="assets.csac.com.bo.Product" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.Product_ID")) {
				local.obj.setProduct_ID(arguments.Product_ID);
			}
			if (IsDefined("arguments.ID")) {
				local.obj.setID(arguments.ID);
			}
			if (IsDefined("arguments.SKU")) {
				local.obj.setSKU(arguments.SKU);
			}
			if (IsDefined("arguments.Product_Category_ID")) {
				local.obj.setProduct_Category_ID(arguments.Product_Category_ID);
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted); 
			}
			if (IsDefined("arguments.Active")) {
				local.obj.setActive(arguments.Active); 
			}
			if (IsDefined("arguments.Product")) {
				local.obj.setProduct(arguments.Product);
			}
			if (IsDefined("arguments.Description")) {
				local.obj.setDescription(arguments.Description);
			}
			if (IsDefined("arguments.System_Name")) {
				local.obj.setSystem_Name(arguments.System_Name);
			}
			if (IsDefined("arguments.Inventory")) {
				local.obj.setInventory(arguments.Inventory); 
			}
			if (IsDefined("arguments.Stock")) {
				local.obj.setStock(arguments.Stock);
			}
			if (IsDefined("arguments.Stock_Warn")) {
				local.obj.setStock_Warn(arguments.Stock_Warn);
			}
			if (IsDefined("arguments.Allow_Back_Order")) {
				local.obj.setAllow_Back_Order(arguments.Allow_Back_Order);
			}
			if (IsDefined("arguments.Download_Only")) {
				local.obj.setDownload_Only(arguments.Download_Only); 
			}
			if (IsDefined("arguments.Package")) {
				local.obj.setPackage(arguments.Package); 
			}
			if (IsDefined("arguments.Package_Only")) {
				local.obj.setPackage_Only(arguments.Package_Only); 
			}
			if (IsDefined("arguments.Package_Quantity")) {
				local.obj.setPackage_Quantity(arguments.Package_Quantity); 
			}
			if (IsDefined("arguments.Sort_Order")) {
				local.obj.setSort_Order(arguments.Sort_Order);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}			
			return local.obj;
		</cfscript>
	</cffunction>
	
	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="Product_ID" required="false" default="" />
		<cfargument name="ID" required="false" default="" />
		<cfargument name="Product_Category_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Active" required="false" default="" />
		<cfargument name="Product" required="false" default="" />
		<cfargument name="Description" required="false" default="" />
		<cfargument name="System_Name" required="false" default="" />
		<cfargument name="Inventory" required="false" default="" />
		<cfargument name="Stock" required="false" default="" />
		<cfargument name="Stock_Warn" required="false" default="" />
		<cfargument name="Allow_Back_Order" required="false" default="" />
		<cfargument name="Download_Only" required="false" default="" />
		<cfargument name="Package_Only" required="false" default="" />
		<cfargument name="Package" required="false" default="" />
		<cfargument name="Package_Quantity" required="false" default="" />
		<cfargument name="Sort_Order" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />
		<cfargument name="productIDs" required="false" default="" />
		<cfargument name="productCategoryIDs" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readProduct">
			<cfprocparam value="#arguments.Product_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Product_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.ID#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Product_Category_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Product_Category_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Active#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Active)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Product#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Product)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Description#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Description)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.System_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.System_Name)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Inventory#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Inventory)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Stock#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Stock)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Stock_Warn#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Stock_Warn)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Allow_Back_Order#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Allow_Back_Order)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Download_Only#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Download_Only)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Package#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Package)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Package_Only#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Package_Only)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Package_Quantity#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Package_Quantity)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Sort_Order#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Sort_Order)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.productIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.productIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.productCategoryIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.productCategoryIDs)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="product" required="true" type="assets.csac.com.bo.Product" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveProduct">
			<cfprocparam value="#product.getProduct_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#product.getID()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(product.getID())) eq 0, true, false)#" />
			<cfprocparam value="#product.getProduct_Category_ID()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(product.getProduct_Category_ID())) eq 0, true, false)#" />
			<cfprocparam value="#product.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getActive()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getProduct()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#product.getDescription()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(product.getDescription())) eq 0, true, false)#" />
			<cfprocparam value="#product.getSystem_Name()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(product.getSystem_Name())) eq 0, true, false)#" />
			<cfprocparam value="#product.getInventory()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getStock()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(product.getStock())) eq 0, true, false)#" />
			<cfprocparam value="#product.getStock_Warn()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(product.getStock_Warn())) eq 0, true, false)#" />
			<cfprocparam value="#product.getAllow_Back_Order()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getDownload_Only()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getPackage()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getPackage_Only()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#product.getPackage_Quantity()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(product.getPackage_Quantity())) eq 0, true, false)#" />
			<cfprocparam value="#product.getSort_Order()#" cfsqltype="CF_SQL_INTEGER" null="false" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="Product_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroyProduct">
			<cfprocparam value="#arguments.Product_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

